<?php 

namespace app\admin\event;

use app\common\model\GoodsType as GoodsTypeModel;
use app\common\utils\JsonService;

class GoodsTypeEvent{

    /*
    * 商品模型列表
    */
    public static function goodsTypeList(){
        $params = array_filter(request()->param());
        $page = ! empty($params['page']) && $params['page'] >= 1 ? $params['page'] : 1;
        $where = [];

        $condition = [
            'where' => $where,
            'order' => ['id' => 'desc'],
                'paginate' => [
                'page' => $page,
                'query' => $params,
            ],
        ];
        $goodsType = GoodsTypeModel::getPageAll($condition);
        return $goodsType;
    }


    /*
    * 新增商品模型
    */
    public static function createGoodsType($data){

        try {
            GoodsTypeModel::create($data);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }

    /*
    * 更新商品模型
    */
    public static function updateGoodsType($data){

        try {
            GoodsTypeModel::updateOne($data, ['id' => $data['id']]);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }


}

